<br/>
<form id="ndk-health-form" method="post" action="<?php echo Yii::app()->createUrl('finance/ExportProduction'); ?>" target="_blank">
	<div class="row">
		<div class="col-md-4">
			<div class="widget box">
				<div class="widget-header">
					<h4><i class="icon-reorder"></i> Production Report</h4>
				</div>
				<div class="widget-content">
				<div class="control-group">
					<label class="control-label">
					Tgl. Input
					<span class="required">*</span>
					</label>
					<div class="controls">
						<div class="input-group">
							<input type="text" class="form-control " id="txt_tgl_input " data-mask="99-99-9999">
						</div>
					</div>
				</div> 
				 <div class="control-group">
					<label class="control-label">
					Nama Marketing
					<span class="required">*</span>
					</label>
					<div class="controls">
						<?php 
echo CHtml::dropDownList('id_marketing', '', CHtml::listData(MstMarketing::model()->findAll(" 1=1  order by id"), 'id','name'),array("empty"=>"--Pilih Marketing--","class"=>"form-control","id"=>"cb_coa","name"=>'id_coa'));							?>
					</div>
				</div> 
				
				<div class="control-group">
					<label class="control-label">
					<input type="radio" value="0" name="chk" checked /> Periode  <input type="radio" value="1" name="chk" /> Bulanan
					<span class="required">*</span>
					</label>
					<div class="controls">
						<div class="input-group" id="div_periode">
							<input type="text" class="form-control input-width-small " style="float:left;" id="txt_tgl_input_awal" data-mask="99-99-9999"> <label>s/d</label>
							<input type="text" class="form-control input-width-small "  id="txt_tgl_input_akhir" data-mask="99-99-9999">
						</div>
						<div class="input-group" id="div_bulanan" style="display:none">
							<select id="bulan" name="bulan" class="form-control  input-width-medium" style="float:left;" >
						<option value="01">Januari</option>
						<option value="02">Februari</option>
						<option value="03">Maret</option>
						<option value="04">April</option>
						<option value="05">Mei</option>
						<option value="06">Juni</option>
						<option value="07">Juli</option>
						<option value="08">Agustus</option>
						<option value="09">September</option>
						<option value="10">Oktober</option>
						<option value="11">November</option>
						<option value="12">Desember</option>
						</select> &nbsp;
						<input id="tahun_bank" class="form-control  input-width-small" type="text" name="tahun_bank" size="100">
						</div>
					</div>
				</div> 
				
				</div>
		</div>
	</div>
	</div>
	
	<div class="row">
		<div class="col-md-2">
		<input type="button" class="btn btn-default btn-warning" id="btn_show_cicil" value="Preview"> 
		<button class="btn btn-primary btn-large" name="yt2" type="submit"><i class="icon-fixed-width">&#xf02f</i>Cetak</button>
		</div>
	</div>
	</form>
	<br/>
	<div class="row">
					<div class="col-md-12">
						<div class="widget box">
							<div class="widget-header">
								<h4><i class="icon-reorder"></i> List Health </h4>
								<div class="toolbar no-padding">
									<div class="btn-group">
										<span class="btn btn-xs widget-collapse"><i class="icon-angle-down"></i></span>
									</div>
								</div>
							</div>
							<div class="widget-content no-padding">
								<table id="tbl_cicilan" class="table table-striped table-bordered table-hover table-checkable table-responsive ">
									<thead>
										<tr>
											
											<th data-class="expand">Client Name </th>
											<th>Periode Polish</th>
											<th>Currency</th>
											<th>Insurance Type</th>
											<th>Gross Premium</th>
											<th>Brokerage</th>
											<th>Class Of Bussiness</th>
										</tr>
									</thead>
									<tbody id="isi_cicilan">
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
				
	<div class="row">
					<div class="col-md-12">
						<div class="widget box">
							<div class="widget-header">
								<h4><i class="icon-reorder"></i> List Non Health </h4>
								<div class="toolbar no-padding">
									<div class="btn-group">
										<span class="btn btn-xs widget-collapse"><i class="icon-angle-down"></i></span>
									</div>
								</div>
							</div>
							<div class="widget-content no-padding">
								<table id="tbl_cicilan" class="table table-striped table-bordered table-hover table-checkable table-responsive ">
									<thead>
										<tr>
											
											<th data-class="expand">Client Name </th>
											<th>Periode</th>
											<th>Currency</th>
											<th>Insurance Type</th>
											<th>Gross Premium</th>
											<th>Brokerage</th>
											<th>Class Of Bussiness</th>
										</tr>
									</thead>
									<tbody id="isi_cicilan2">
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
				

<div id="modalProcess" class="modal fade in" style="display: none;" aria-hidden="false">
												<div class="modal-dialog" style="width:250px;">
													<div class="modal-content">
														<div class="modal-body">
															<div class="alert alert-info fade in" id="div_process">
															Waiting Process..
															</div>
															<div class="alert alert-info fade in" id="div_sukses" style="display:none;">
															Success Process..
															</div>
														</div>
														<div class="modal-footer">
															<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
															
														</div>
													</div><!-- /.modal-content -->
												</div><!-- /.modal-dialog -->
											</div>

<script type="text/javascript">
$('input[name="chk"]').change(function() {
    if(this.value == "0"){
		$("#div_periode").show();
		$("#div_bulanan").hide();
	}else{
		$("#div_periode").hide();
		$("#div_bulanan").show();
	}
});
function formatCurrency(total) {
    var neg = false;
    if(total < 0) {
        neg = true;
        total = Math.abs(total);
    }
    return (neg ? "" : '') + parseFloat(total, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString();
}

$("#btn_show_cicil").click(function(e){
	var status = "";
	var action = "";
	var isi_cicilan = "";
	var isi_cicilan2 = "";
	$.ajax({
			type:"POST",
            url:"<?php echo Yii::app()->createUrl('/Soa/showSoaProduction'); ?>",
			data:"",
			dataType:"json",
            success:function(data){
				var total_health_rp = parseInt(0);
				var total_health_dolar = parseInt(0);
				var total_health_euro = parseInt(0);
				
				var total_healthbroker_rp = parseInt(0);
				var total_healthbroker_dolar = parseInt(0);
				var total_healthbroker_euro = parseInt(0);
				
				var total_nonhealth_rp = parseInt(0);
				var total_nonhealth_dolar = parseInt(0);
				var total_nonhealth_euro = parseInt(0);
				
				var total_nonhealthbroker_rp = parseInt(0);
				var total_nonhealthbroker_dolar = parseInt(0);
				var total_nonhealthbroker_euro = parseInt(0);
				var minus = "";
				var minus_b = "";
				var tanda = "";
				
				for(var i=0;i<data.jsonShowInternal.length;i++){
					if(data.jsonShowInternal[i].type=="RP"){
						minus = "(";
						minus_b = ")";
						tanda = "-";
					}
					isi_cicilan += "<tr>" +
					"<td>"+data.jsonShowInternal[i].nama_client+"</td>"+
					"<td>"+data.jsonShowInternal[i].start_periode+" s/d "+data.jsonShowInternal[i].end_periode+"</td>"+
					"<td>"+data.jsonShowInternal[i].currency+"</td>"+
					"<td>Kesehatan</td>"+
					"<td align='right'>"+minus+formatCurrency(data.jsonShowInternal[i].nominal)+minus_b+"</td>"+
					"<td align='right'>"+minus+formatCurrency(data.jsonShowInternal[i].brokerage)+minus_b+"</td>"+
					"<td>"+data.jsonShowInternal[i].type+"</td>"+
					"</tr>";
					
					if(data.jsonShowInternal[i].currency == "Rupiah"){
						if(data.jsonShowInternal[i].type=="RP" || data.jsonShowInternal[i].type=="CR" || data.jsonShowInternal[i].type=="CA"){
							total_health_rp -= Math.abs(data.jsonShowInternal[i].nominal);
							total_healthbroker_rp -= Math.abs(data.jsonShowInternal[i].brokerage);
						}else{
							total_health_rp += Math.abs(data.jsonShowInternal[i].nominal);
							total_healthbroker_rp += Math.abs(data.jsonShowInternal[i].brokerage);
						}
					}else if(data.jsonShowInternal[i].currency == "Dollar"){
						if(data.jsonShowInternal[i].type=="RP" || data.jsonShowInternal[i].type=="CR" || data.jsonShowInternal[i].type=="CA"){
							total_health_dolar -= Math.abs(parseInt(data.jsonShowInternal[i].nominal));
							total_healthbroker_dolar -= Math.abs(parseInt(data.jsonShowInternal[i].brokerage));
						}else{
							total_health_dolar += Math.abs(parseInt(data.jsonShowInternal[i].nominal));
							total_healthbroker_dolar += Math.abs(parseInt(data.jsonShowInternal[i].brokerage));
						}
					}else{
						if(data.jsonShowInternal[i].type=="RP" || data.jsonShowInternal[i].type=="CR" || data.jsonShowInternal[i].type=="CA"){
							total_health_euro -= Math.abs(parseInt(data.jsonShowInternal[i].nominal));
							total_healthbroker_euro -= Math.abs(parseInt(data.jsonShowInternal[i].brokerage));
						}else{
							total_health_euro += Math.abs(parseInt(data.jsonShowInternal[i].nominal));
							total_healthbroker_euro += Math.abs(parseInt(data.jsonShowInternal[i].brokerage));
						}
					}
					
				}
				
				isi_cicilan += "<tr>" +
									"<td colspan='4' align='right'>TOTAL RUPIAH</td>"+
									"<td align='right'>"+formatCurrency(total_health_rp)+"</td>"+
									"<td align='right'>"+formatCurrency(total_healthbroker_rp)+"</td>"+
									"<td>-</td>"+
							   "</tr>";
							   
				isi_cicilan += "<tr>" +
									"<td colspan='4' align='right'>TOTAL DOLAR</td>"+
									"<td align='right'>"+formatCurrency(total_health_dolar)+"</td>"+
									"<td align='right'>"+formatCurrency(total_healthbroker_dolar)+"</td>"+
									"<td>-</td>"+
							   "</tr>";
							   
				isi_cicilan += "<tr>" +
									"<td colspan='4' align='right'>TOTAL EURO</td>"+
									"<td align='right'>"+formatCurrency(total_health_euro)+"</td>"+
									"<td align='right'>"+formatCurrency(total_healthbroker_euro)+"</td>"+
									"<td>-</td>"+
							   "</tr>";
				$("#isi_cicilan").html(isi_cicilan);
				
				for(var y=0;y<data.jsonShowInternal2.length;y++){
					isi_cicilan2 += "<tr>" +
					"<td>"+data.jsonShowInternal2[y].nama_client+"</td>"+
					"<td>"+data.jsonShowInternal2[y].start_periode+" s/d "+data.jsonShowInternal2[y].end_periode+"</td>"+
					"<td>"+data.jsonShowInternal2[y].currency+"</td>"+
					"<td>"+data.jsonShowInternal2[y].jns_insurance+"</td>"+
					"<td align='right'>"+formatCurrency(data.jsonShowInternal2[y].nominal)+"</td>"+
					"<td align='right'>"+formatCurrency(data.jsonShowInternal2[y].brokerage)+"</td>"+
					"<td>"+data.jsonShowInternal2[y].type+"</td>"+
					"</tr>";
					
					if(data.jsonShowInternal2[y].currency == "Rupiah"){
						if(data.jsonShowInternal2[y].type=="RP" || data.jsonShowInternal2[y].type=="CR" || data.jsonShowInternal2[y].type=="CA"){
							total_nonhealth_rp -= Math.abs(data.jsonShowInternal2[y].nominal);
							total_nonhealthbroker_rp -= Math.abs(data.jsonShowInternal2[y].brokerage);
						}else{
							total_nonhealth_rp += Math.abs(data.jsonShowInternal2[y].nominal);
							total_nonhealthbroker_rp += Math.abs(data.jsonShowInternal2[y].brokerage);
						}
					}else if(data.jsonShowInternal2[y].currency == "Dollar"){
						if(data.jsonShowInternal2[y].type=="RP" || data.jsonShowInternal2[y].type=="CR" || data.jsonShowInternal2[y].type=="CA"){
							total_nonhealth_dolar -= Math.abs(data.jsonShowInternal2[y].nominal);
							total_nonhealthbroker_dolar -= Math.abs(data.jsonShowInternal2[y].brokerage);
						}else{
							total_nonhealth_dolar += Math.abs(data.jsonShowInternal2[y].nominal);
							total_nonhealthbroker_dolar += Math.abs(data.jsonShowInternal2[y].brokerage);
						}
					}else{
						if(data.jsonShowInternal2[y].type=="RP" || data.jsonShowInternal2[y].type=="CR" || data.jsonShowInternal2[y].type=="CA"){
							total_nonhealth_euro -= Math.abs(data.jsonShowInternal2[y].nominal);
							total_nonhealthbroker_euro -= Math.abs(data.jsonShowInternal2[y].brokerage);
						}else{
							total_nonhealth_euro += Math.abs(data.jsonShowInternal2[y].nominal);
							total_nonhealthbroker_euro += Math.abs(data.jsonShowInternal2[y].brokerage);
						}
					}
				
				}
				
				isi_cicilan2 += "<tr>" +
									"<td colspan='4' align='right'>TOTAL RUPIAH</td>"+
									"<td align='right'>"+formatCurrency(total_nonhealth_rp)+"</td>"+
									"<td align='right'>"+formatCurrency(total_nonhealthbroker_rp)+"</td>"+
									"<td>-</td>"+
							   "</tr>";
							   
				isi_cicilan2 += "<tr>" +
									"<td colspan='4' align='right'>TOTAL DOLAR</td>"+
									"<td align='right'>"+formatCurrency(total_nonhealth_dolar)+"</td>"+
									"<td align='right'>"+formatCurrency(total_nonhealthbroker_dolar)+"</td>"+
									"<td>-</td>"+
							   "</tr>";
							   
				isi_cicilan2 += "<tr>" +
									"<td colspan='4' align='right'>TOTAL EURO</td>"+
									"<td align='right'>"+formatCurrency(total_nonhealth_euro)+"</td>"+
									"<td align='right'>"+formatCurrency(total_nonhealthbroker_euro)+"</td>"+
									"<td>-</td>"+
							   "</tr>";		   
				
				$("#isi_cicilan2").html(isi_cicilan2);
			}
	});
});//end click


</script>